﻿using System;
using System.Text.RegularExpressions;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class public_html_NewSiteTest_Releaseliste : System.Web.UI.Page
{
    public string SpilID = "";
    public string Format = "";
    protected void Page_Load(object sender, EventArgs e)
    {
        DateFromMySql NewDate = new DateFromMySql();
        ReviewerMySql SQL = new ReviewerMySql();
        int i = 0;
        int x = 0;

        string SQLsaetning = "";

        string Format = Request.QueryString["Format"];
        string Search = Request.QueryString["Ord"];
        string FoNavn = Request.QueryString["Navn"];
        string Emne = Request.QueryString["Emne"];

        HyperLinkUpdate.NavigateUrl = "?Emne=Update";
        HyperLinkScreenshots.NavigateUrl = "?Emne=Screenshots";
        HyperLinkRygte.NavigateUrl = "?Emne=Rygte";
        HyperLinkPressemeddelse.NavigateUrl = "?Emne=Pressemeddelelse";
        HyperLinkNyUdgivelse.NavigateUrl = "?Emne=Ny Udgivelse";
        HyperLinkNyhed.NavigateUrl = "?Emne=Nyhed";

        HyperLinkXbox.NavigateUrl = "?Navn=Xbox 360&Format=1";
        HyperLinkPC.NavigateUrl = "?Navn=PC&Format=2";
        HyperLinkPlayStation3.NavigateUrl = "?Navn=Playstation 3&Format=3";
        HyperLinkNintendoWii.NavigateUrl = "?Navn=Nintendo Wii&Format=4";

        if (Search == null && Emne == null && Format == null)
        {
            SQLsaetning = "SELECT * FROM V2_Nyhed ORDER BY id DESC LIMIT 20";
            lblOverskrift.Text = "Seneste 20 nyheder";
        }

        if (Emne != null && Search == null && Format == null)
        {
            SQLsaetning = "SELECT * FROM V2_Nyhed WHERE Emne = '" + Emne + "' ORDER BY id DESC LIMIT 20";
            if (Emne == "Nyhed")
            {
                lblOverskrift.Text = "Seneste 20  nyheder";
            }
            else if (Emne == "Pressemeddelelse")
            {
                lblOverskrift.Text = "Seneste 20 pressemeddelelser";
            }
            else if (Emne == "Screenshots")
            {
                lblOverskrift.Text = "Seneste 20 screenshots";
            }
            else if (Emne == "Update")
            {
                lblOverskrift.Text = "Seneste 20 updates";
            }
            else if (Emne == "Ny Udgivelse")
            {
                lblOverskrift.Text = "Seneste 20 nye udgivelser";
            }
            else if (Emne == "Rygte")
            {
                lblOverskrift.Text = "Seneste 20 rygter";
            }
        }

        if (Format != null)
        {
            SQLsaetning = "SELECT V2_Nyhed.* FROM V2_NewsFormat JOIN V2_Nyhed ON V2_Nyhed.NewsID = V2_NewsFormat.NewsID WHERE Format = " + Format + " ORDER BY V2_Nyhed.id DESC LIMIT 20";
            lblOverskrift.Text = "Seneste 20  " + FoNavn + " nyheder";
        }

        if (Search != null)
        {
            SQLsaetning = "SELECT * FROM V2_Nyhed WHERE Titel LIKE '%" + Search + "%' OR Header LIKE '%" + sender + "%' OR Tekst LIKE '%" + Search + "%' ORDER BY id DESC";
            lblOverskrift.Text = "Søgning: " + Search;
        }

        DivResult.InnerHtml += "<table width=\"100%\">";
        OdbcDataReader MainReader = SQL.ExecuteReader(SQLsaetning);
        while (MainReader.Read())
        {
            string ID = MainReader["id"].ToString();
            if (ID.Length == 3) ID = "0" + ID;
            if (ID.Length == 2) ID = "00" + ID;
            if (ID.Length == 1) ID = "000" + ID;
            string Titel = MainReader["Titel"].ToString();
            Titel = Regex.Replace(Titel, " — ", "-");
            Titel = Regex.Replace(Titel, " - ", "-");
            Titel = Regex.Replace(Titel, " ", "-");
            Titel = Regex.Replace(Titel, ":", "");
            Titel = Regex.Replace(Titel, "&", "and");
            if (x == 0)
            {
                DivResult.InnerHtml += "<tr><td class=\"TDrowTwo\"><a href=\"" + ID + "-" + Titel + "-nyhed.aspx\">" + MainReader["Titel"].ToString() + "</a></td><td class=\"TDrowTwo\">" + MainReader["Emne"].ToString() + "</td><td class=\"TDrowTwo\">" + NewDate.GetDate(MainReader["Dato"].ToString()) + "</td></tr>";
                x++;
            }
            else
            {
                DivResult.InnerHtml += "<tr><td><a href=\"" + ID + "-" + Titel + "-nyhed.aspx\">" + MainReader["Titel"].ToString() + "</a></td><td>" + MainReader["Emne"].ToString() + "</td><td>" + NewDate.GetDate(MainReader["Dato"].ToString()) + "</td></tr>";
                x = 0;
            }
        }
        DivResult.InnerHtml += "</table>";
    }
}
